/**
 * Created:	2001-7-22
 * By:		eeorange
 * About: 	uva 146 - ID Codes
 * Status:	AC 0.008
 */

#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
		//freopen("data.in", "r", stdin);
	#endif
	
	char arr[51];
	for(;;){
		scanf("%s", arr);
		if(strcmp(arr, "#") == 0) break;
			
		if(next_permutation(arr, arr+strlen(arr)))
			printf("%s\n", arr);
		else 
			printf("No Successor\n");
	}
	
	#ifndef ONLINE_JUDGE
		printf("\nTime used = %.3lf\n", (double)clock()/CLOCKS_PER_SEC);
		printf("****** END ******\n");
	#endif
	return 0;
}





